{% extends "base.html" %}

{% block title %}celery_test{% endblock %}

{% block head %}
    {{ super() }}
    <style>
        p {
            font-size: 30px;
            color: springgreen;
        }
    </style>
{% endblock %}

{% block page_content %}
    <h1>Celery 测试</h1>
    <a class="btn btn-danger" onclick="haoshi()">这是一个耗时任务</a>
    <p hidden="hidden" id="haoshi"></p>
    <a class="btn btn-info" onclick="chaxun()">查询Redis数据库</a>
{% endblock %}

{% block scripts %}
    {{ super() }}
    <script type="text/javascript" src="{{ url_for('static', filename='js/jquery-3.4.1.min.js') }}"></script>
    <script type="text/javascript">
        function haoshi() {
            $.ajax({
                url: "/oltools/haoshi",
                type: "GET",
                dataType: "JSON",
                success: function (response) {
                    $("#haoshi").removeAttr("hidden").text(response.msg)
                },
                error: function () {
                    alert('失败');
                }
            });
        }

        function chaxun() {
            $.ajax({
                url: "/oltools/chaxun",
                type: "GET",
                dataType: "JSON",
                success: function (response) {
                    if (response.result !== null) {
                        alert(response.result);
                    } else {
                        alert('数据库中没有数据');
                    }
                },
                error: function () {
                    alert('失败');
                }
            });
        }
    </script>
{% endblock %}